#include "blink.h"

Blink::Blink()
{
}

Blink::Blink(GpioPort port, int pin, int normalLevel, 
             int ontime, int offtime, int repeat)
{
    SetInfo(port, pin, normalLevel, ontime, offtime, repeat);
}

Blink::~Blink()
{
}

void Blink::SetInfo(GpioPort port, int pin, int normalLevel, 
                    int ontime, int offtime, int repeat)
{
    m_port = port;
    m_pin = pin;
    m_normalLevel = normalLevel;
    m_ontime = ontime;
    m_offtime = offtime;
    m_repeats = repeat;

    m_currentVal = normalLevel;
    ToggleImpl();
}

void Blink::Start()
{
    if(m_repeats == 0)
        return;
    
    m_timer.Start();
}

void Blink::Stop()
{
    m_timer.Stop();
}

void Blink::ToggleImpl()
{
//    CALL_Peripheral(SOC_Gpio, "gpio", 0, Write(m_port, m_pin, m_currentVal));
//    if(m_currentVal == 0)
//    {
//        m_timer.SetInterval(m_ontime);
//    }
//    else
//    {
//        m_timer.SetInterval(m_offtime);
//    }

    m_currentVal = 1 - m_currentVal;
}
